import gtk
import threading
import os
import urllib

__VERSION_STRING__="0.2"

class WorkerThread_Update(threading.Thread):
	def __init__(self):
		threading.Thread.__init__(self)
	def run(self):
		url=urllib.urlopen("http://mmxfer.googlecode.com/svn/latest")
		if url.getcode()==200:
			latest=url.readline().split()[0]
			url.close()
			if __VERSION_STRING__!=latest:
				print "Update available!"
				gtk.gdk.threads_enter()
				info="A new version of MMXfer is available!\n(Current version is '"+__VERSION_STRING__+"', latest version is '"+latest+"')\nWould you like to go to the download site?"
				dlg=gtk.MessageDialog(buttons=gtk.BUTTONS_YES_NO,message_format=info,type=gtk.MESSAGE_INFO)
				dlg.set_title("MMXfer Error")
				dlg.connect("response",self.Response)
				dlg.show()
				gtk.gdk.threads_leave()
	def Response(self,dialog, response):
		if response==gtk.RESPONSE_YES:
			os.system("xdg-open http://code.google.com/p/mmxfer/downloads/list")
		dialog.destroy()

